//
//  SearchVC.m
//  MedicalCare
//
//  Created by lbh on 2021/10/11.
//  Copyright © 2021 hs. All rights reserved.
//

#import "SearchVC.h"
#import "SearchHeadView.h"
#import "SearchHistorView.h"
#import "SearchTabCell.h"
#import "EmptyView.h"
#import "PlayViewController.h"
#import "SearchTitleModel.h"
#import "SearchTitleSectionView.h"
#import "SearchTeacherCell.h"
#import "Teacher.h"
#import "OnLineTeacherDetailVC.h"
#import "GCAVPlayer.h"

@interface SearchVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)SearchHeadView *headView;
@property (nonatomic,strong)SearchHistorView *historyView;
//@property (nonatomic,strong)UIButton *leftSearchButton;
//@property (nonatomic,strong)UIButton *rightSearchButton;
@property (nonatomic,strong)UIView *lineView;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic, strong) NSArray *datas;
@property (nonatomic, strong) NSMutableArray *allDatas;
@property (nonatomic, assign) NSInteger currentIndex;
//@property (nonatomic,strong)NSArray *leftDatas;//标题
//@property (nonatomic,strong)NSArray *rightDatas;//文稿
@property (nonatomic,strong)EmptyView *emptyView;
@property (nonatomic, strong)ObjectAFNetWorking* objectAFNet;
@property (nonatomic,copy)NSString *keyStr;
@property (nonatomic, weak) UIView *tipView;
@property (nonatomic, weak) UIView *searchIndexView;
@property (nonatomic, weak) UILabel *searchResultLabel;
@property (nonatomic, weak) UILabel *searchTimeLabel;
@property (nonatomic, assign) CGFloat hideTipY;
@property (nonatomic, assign) CGFloat showTipY;

@property (nonatomic, strong) NSMutableArray *cacheList;

@end

@implementation SearchVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeUI];
    [self getSearchHotRequest];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    if ([SUPlayerManager manager].currentSong) {
        CGFloat height = 0;
        if (@available(iOS 13.0, *)) {
            NSSet *set = [UIApplication sharedApplication].connectedScenes;
            UIWindowScene *windowScene = [set anyObject];
            UIWindow *window = windowScene.windows.firstObject;
            height = window.safeAreaInsets.bottom;
        } else if (@available(iOS 11.0, *)) {
            UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
            height = window.safeAreaInsets.bottom;
        }
        height += 49;

        [[SUPlayerManager manager].bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo([UIApplication sharedApplication].keyWindow);
            make.bottom.equalTo([UIApplication sharedApplication].keyWindow).offset(-height+49);
            make.height.mas_equalTo(60);
        }];
    }
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - Private
- (void)request{
}
- (void)makeUI {
    
    self.view.backgroundColor = UIColor.whiteColor;
    self.objectAFNet=[[ObjectAFNetWorking alloc]init];
    
    CGFloat navH = topHeight + wid(15);
    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,navH)];
    view.backgroundColor=AppMainColor;
    [self.view addSubview:view];
    UIButton* leftbtn=[UIButton new];
    leftbtn.frame=CGRectMake(wid(20),StatusBarHeight+(topHeight-StatusBarHeight-wid(33))/2.0,wid(40),wid(40));
    [leftbtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    leftbtn.titleLabel.font=[UIFont systemFontOfSize:12];
    [leftbtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:leftbtn];
    
    [view addSubview:self.headView];
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(leftbtn.mas_centerY);
        make.left.mas_equalTo(leftbtn.mas_right).offset(00);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    
    UIView *searchIndexView = [[UIView alloc] init];
    [self.view addSubview:searchIndexView];
    self.searchIndexView = searchIndexView;
    searchIndexView.backgroundColor = [UIColor whiteColor];
    [searchIndexView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(view.mas_bottom);
        make.height.mas_equalTo(50);
    }];
    
    NSArray *titles = @[@"标题", @"文稿", @"讲师"];
    CGFloat btnW = fk_adjustW(72);
    CGFloat margin = (fkScreenW - (btnW * 3)) / (titles.count + 1);
    CGFloat btnX = margin;
    CGFloat btnY = 0;
    CGFloat btnH = 50;
    for (NSInteger index = 0; index < titles.count; index++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [searchIndexView addSubview:btn];
        [btn setTitle:titles[index] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"多选框-没有选中"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
        [btn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        [btn setTitleColor:AppMainColor forState:UIControlStateSelected];
        btn.titleLabel.font = kFont(16);
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
        [btn addTarget:self action:@selector(indexBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        if (index == 0) {
            self.currentIndex = index;
            btn.selected = YES;
        }
        btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
        btnX += (btnW + margin);
    }
    
//    [searchIndexView addSubview:self.leftSearchButton];
//    [self.leftSearchButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.bottom.offset(0);
//        make.width.mas_equalTo(SCREEN_WIDTH/2);
//    }];
//
//    [searchIndexView addSubview:self.rightSearchButton];
//    [self.rightSearchButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.right.bottom.offset(0);
//        make.width.mas_equalTo(SCREEN_WIDTH/2);
//    }];
    
    [self.view addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(searchIndexView.mas_bottom).offset(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.view addSubview:self.historyView];
    [self.historyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(0);
        make.left.bottom.right.mas_equalTo(0);
    }];
    
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(self.lineView.mas_bottom);
    }];
    
    self.emptyView.hidden = YES;
    [self.view addSubview:self.emptyView];
    [self.emptyView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(searchIndexView.mas_bottom).offset(150);
        make.centerX.mas_equalTo(self.view.mas_centerX);
    }];
    
    // 搜索数展示的tipview
    UIView *tipView = [[UIView alloc] init];
    [self.view insertSubview:tipView atIndex:0];
    [self.view insertSubview:searchIndexView atIndex:0];
    self.tipView = tipView;
    [tipView fk_viewCornerRadius:7 borderWidth:0 borderColor:nil];
    
    UIView *container = [[UIView alloc] init];
    [tipView addSubview:container];
    tipView.backgroundColor = fkColor(203, 231, 190);
    
    UILabel *leftLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor333333];
    [container addSubview:leftLabel];
    self.searchResultLabel = leftLabel;
    
    UILabel *searchTimeLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666];
    [container addSubview:searchTimeLabel];
    self.searchTimeLabel = searchTimeLabel;
    
    CGFloat tipH = fk_adjustW(4 + 40);
    CGFloat tipY = navH - tipH;
    self.hideTipY = tipY;
    self.showTipY = navH - fk_adjustW(4);
    tipView.frame = CGRectMake(0, tipY, fkScreenW, tipH);
    
    [container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.offset(0);
        make.top.offset(fk_adjustW(4));
    }];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.offset(0);
        make.right.offset(-110);
    }];
    [searchTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.centerY.offset(0);
    }];
}

- (void)showTip
{
    [UIView animateWithDuration:0.25 animations:^{
        self.tipView.fk_top = self.showTipY;
    } completion:^(BOOL finished) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:0.25 animations:^{
                self.tipView.fk_top = self.hideTipY;
            }];
        });
    }];
}

///搜索操作 tag 0输入框内容 1清空 2取消 3搜索
- (void)searchHeadViewBlockMethod:(NSInteger)tag{
    NSString *text = self.headView.searchTextField.text;
    if (tag == 0) {
        
    } else if (tag == 1){
        self.emptyView.hidden = YES;
        self.tableView.hidden = YES;
        self.keyStr = @"";
        [self.historyView showSearchHistory];
    } else if (tag == 2){
        [self.navigationController popViewControllerAnimated:NO];
    } else if (tag == 3){
        [self.historyView disMissSearchHistory];
        if ([FKCacheTool isOpenSearchRecord]) {
            [self.historyView addHistory:text];
        }
        [self loadDataSearchMethod:text];
    }
}
///数据搜索
- (void)loadDataSearchMethod:(NSString *)key{
    [self getSearchContentRequest:key];
}

#pragma mark - NetWork
//获取搜索热词
- (void)getSearchHotRequest{
    [self.view showBusyHUD];
    [self.objectAFNet getUrlStr:[NSString stringWithFormat:@"%@/api/index/HotSearch",server_addr] finish:^(id  _Nonnull dataString) {
        [self.view hideBusyHUD];
        NSDictionary* dic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dic);
        id data = dic[@"data"];
        if ([data isKindOfClass: [NSArray class]]) {
            NSArray *dataArray = data;
            self.historyView.hotArray = dataArray;
        }
        else{
            self.historyView.hotArray = @[];
        }
    } andError:^(NSError * _Nonnull error) {
        self.historyView.hotArray = @[];
        [self.view hideBusyHUD];
    }];
}
//获取搜索内容
- (void)getSearchContentRequest:(NSString *)key{
    self.keyStr = key;
    [self.view showBusyHUD];
    NSString *keyword = @"";
    NSString *tag = @"";
    NSString *title = @"";
    NSString *introduce = @"";
    NSString *teacher = @"";
    if (self.currentIndex == 0) {
        title = key;
    } else if (self.currentIndex == 1) {
        introduce = key;
    } else {
//        teacher = key;
        keyword = key;
    }
    NSString *media_class_id = self.searchID;
    NSString *url = [NSString stringWithFormat:@"%@/api/index/AudioList", HostURL];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"keyword"] = keyword;
    param[@"tag"] = tag;
    param[@"title"] = title;
    param[@"introduce"] = introduce;
//    param[@"teacher"] = teacher;
    param[@"media_class_id"] = media_class_id;
    
    NSDate *begin = [NSDate date];
    [self.objectAFNet postUrlStr:url parames:param finish:^(id  _Nonnull dataString) {
        [self.view hideBusyHUD];
        NSDate *end = [NSDate date];
        NSTimeInterval interval = [end timeIntervalSinceDate:begin];
        float seconds = (float)interval; // 将时间差转换为整数秒数
        self.searchTimeLabel.text = fkFORMAT(@"逝去%.2f秒", seconds);
        
        FKBaseResult *result = [FKBaseResult mj_objectWithKeyValues:[dataString mj_JSONObject]];
        if (result.isSuccess) {
            NSArray *list = [SearchTitleModel mj_objectArrayWithKeyValuesArray:result.data[@"media"]];
            if (self.currentIndex == 2) list = [Teacher mj_objectArrayWithKeyValuesArray:result.data[@"teacher"]];
            self.allDatas[self.currentIndex] = list;
            self.datas = list;
            [self searcgContenData];
            // 设置tip的内容
            UIButton *selectedBtn = self.searchIndexView.subviews[self.currentIndex];
            NSString *indexTitle = selectedBtn.titleLabel.text;
            NSInteger num = [result.data[@"sum"] integerValue];
            self.searchResultLabel.text = fkFORMAT(@"%@-查\"%@\"共%zd个", indexTitle, key, num);
            self.tipView.backgroundColor = num == 0 ? fkColor(227, 184, 186) : fkColor(203, 231, 190);
            [self.searchResultLabel setAttribute:self.searchResultLabel.text diff:key diffColor:UIColor.redColor diffFont:self.searchResultLabel.font];
        }
        [self showTip];
    } andError:^(NSError * _Nonnull error) {
        self.allDatas[self.currentIndex] = @[];
        self.datas = @[];
        [self.view hideBusyHUD];
        [self searcgContenData];
    }];
}
- (void)searcgContenData{
    self.tableView.hidden = NO;
    self.historyView.hidden = YES;
    self.emptyView.hidden = YES;
    NSArray *list = self.allDatas[self.currentIndex];
    if (list.count == 0) {
        self.emptyView.hidden = false;
    }
//    if (self.leftSearchButton.isSelected) {
//        if (self.leftDatas.count == 0) {
//            self.emptyView.hidden = NO;
//        }
//    } else{
//        if (self.rightDatas.count == 0) {
//            self.emptyView.hidden = NO;
//        }
//    }
    [self.tableView reloadData];
}
//将字符串特定的1个字变成红色
- (void)redXingWithLabel:(UILabel *)tempLabel atIndex:(NSInteger)tempIndex {
    NSMutableAttributedString * tempString = [[NSMutableAttributedString alloc] initWithString: tempLabel.text];
    [tempString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(tempIndex, 1)];
    tempLabel.attributedText = tempString;
}
#pragma mark - Action
- (void)indexBtnClicked:(UIButton *)btn
{
    if (btn.isSelected) return;
    for (UIButton *temp in self.searchIndexView.subviews) {
        if ([btn isEqual:temp]) {
            temp.selected = true;
            self.currentIndex = [self.searchIndexView.subviews indexOfObject:temp];
        } else {
            temp.selected = false;
        }
    }
    
    NSArray *list = self.allDatas[self.currentIndex];
    if (![NSString isEmpty:self.keyStr] && list.count == 0) {
        // 2023-05-19：要求切换tab的时候不自动搜索，需要用户手动操作进行搜索
//        [self getSearchContentRequest:self.keyStr];
    } else {
        self.emptyView.hidden = true;
    }
    self.datas = list;
    [self.tableView reloadData];
}
-(void)leftBtnAction{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)dataLocalDataStorage:(NSMutableDictionary *)data {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSMutableArray *searchHistory = [defaults objectForKey:@"searchHistory"];
    [searchHistory addObject:data];
    [defaults setObject:searchHistory forKey:@"searchHistory"];
    [defaults synchronize];
}

#pragma mark - TbaleViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.currentIndex == 2) return 1;
    return self.datas.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.currentIndex == 2) {
        return self.datas.count;
    }
    SearchTitleModel *group = self.datas[section];
    return group.list.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.currentIndex == 2) {
        Teacher *model = self.datas[indexPath.row];
        return model.cellH;
    }
    SearchTitleModel *group = self.datas[indexPath.section];
    MediaModel *model = group.list[indexPath.row];
    return model.cellH;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (self.currentIndex == 2) return nil;
    SearchTitleSectionView *header = [SearchTitleSectionView sectionView:tableView];
    header.data = self.datas[section];
    return header;
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (self.currentIndex == 2) return 0;
      return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *emkey = [self.keyStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    SearchTitleModel *group = self.datas[indexPath.section];
    if (self.currentIndex == 0) {
        SearchTabCell *cell = [SearchTabCell cellWith:tableView];
        cell.data = group.list[indexPath.row];
        [cell setTitlehigh:emkey];
        return cell;
    } else if (self.currentIndex == 1) {
        SearchWenGaoTabCell *cell = [SearchWenGaoTabCell cellWith:tableView];
        cell.data = group.list[indexPath.row];
        [cell setTitlehigh:emkey];
        return cell;
    } else {
        SearchTeacherCell *cell = [SearchTeacherCell cellWith:tableView];
        cell.data = self.datas[indexPath.row];
        [cell setTitlehigh:emkey];
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.currentIndex == 2) {
        OnLineTeacherDetailVC *vc = [[OnLineTeacherDetailVC alloc]init];
        Teacher *model = self.datas[indexPath.row];
        vc.dataDict = [model mj_JSONObject];
//        vc.medilassID = self.mediClassID;
//        vc.hidesBottomBarWhenPushed=YES;
        fkPushNav(vc);
    } else {

        SearchTitleModel *group = self.datas[indexPath.section];
        MediaModel *model = group.list[indexPath.row];
        [self updateSelectedState:indexPath];

//        [[GCAVPlayer shared] play:list andindex:0 ViewStatue:1 andIsAudio:YES];
        
        BOOL isCache = NO;
        NSInteger indexNum1 = 0;
        for (int i = 0; i < self.cacheList.count; i++) {
            NSDictionary *d = self.cacheList[i];
            NSString *did = [NSString stringWithFormat:@"%@", d[@"id"]];
            if ([did isEqualToString:model.id]) {
                indexNum1 = i;
                isCache = YES;
                break;
            }
        }
        
        if (isCache) {
            [SUPlayerManager manager].currentSongIndex = indexNum1;
            [SUPlayerManager manager].songList = self.cacheList;
        } else {
            self.tableView.userInteractionEnabled = NO;
            [[[ObjectAFNetWorking alloc]init] getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatelist?id=%@",server_addr, model.media_class_id] finish:^(id  _Nonnull dataString) {

                NSDictionary* dic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
                NSArray *asss = dic[@"data"][@"list"];
                NSInteger indexNum = 0;
                for (int i = 0; i < asss.count; i++) {
                    NSDictionary *d = asss[i];
                    NSString *did = [NSString stringWithFormat:@"%@", d[@"id"]];
                    if ([did isEqualToString:model.id]) {
                        indexNum = i;
                        break;
                    }
                }
                
                if (!((indexNum == [SUPlayerManager manager].currentSongIndex) && [asss isEqualToArray:[SUPlayerManager manager].songList])) {
                    [SUPlayerManager manager].currentSongIndex = indexNum;
                    [SUPlayerManager manager].songList = asss.mutableCopy;
                    self.cacheList = asss.mutableCopy;
                }
                self.tableView.userInteractionEnabled = YES;
            } andError:^(NSError * _Nonnull error) {
                self.tableView.userInteractionEnabled = YES;
            }];
        }
    }
    
}

- (void)updateSelectedState:(NSIndexPath *)indexPath
{
    SearchTitleModel *group = self.datas[indexPath.section];
    for (SearchTitleModel *group in self.datas) {
        NSInteger i = [self.datas indexOfObject:group];
        for (MediaModel *model in group.list) {
            NSInteger j = [group.list indexOfObject:model];
            model.selected = (i == indexPath.section && j == indexPath.row);
        }
    }
    [self.tableView reloadData];
}

#pragma mark - lazy
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.estimatedRowHeight = 44;
        _tableView.estimatedSectionFooterHeight = 1.5;
        _tableView.estimatedSectionHeaderHeight = 1.5;
//        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15);
//        _tableView.separatorColor = [UIColor fk_colorWithHex:0x979797 alpha:0.54];
        _tableView.separatorColor = fkBgColor;
        [self.view addSubview:_tableView];
        _tableView.backgroundColor = [UIColor whiteColor];
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
            self.edgesForExtendedLayout = UIRectEdgeAll;
        }
        if (@available(iOS 15.0, *)) {
            [_tableView setValue:@0 forKey:@"sectionHeaderTopPadding"];
        }
        [_tableView registerClass:[SearchTabCell class] forCellReuseIdentifier:@"SearchTabCell"];
        [_tableView registerClass:[SearchWenGaoTabCell class] forCellReuseIdentifier:@"SearchWenGaoTabCell"];
        _tableView.hidden = YES;
        _tableView.tableHeaderView = [UIView new];
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_HEIGHT, 60)];
    }
    return _tableView;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = AppMainGrayColor;
    }
    return _lineView;
}

- (SearchHeadView *)headView{
    if (!_headView) {
        _headView  = [[SearchHeadView alloc]init];
        [_headView.searchTextField becomeFirstResponder];
        WeakSelf(wekSlf)
        [_headView setSearchHeadViewBlock:^(NSInteger tag) {
            [wekSlf searchHeadViewBlockMethod:tag];
        }];
    }
    return _headView;
}
- (SearchHistorView *)historyView{
    if (!_historyView) {
        _historyView  = [[SearchHistorView alloc]init];
        WeakSelf(wekSlf)
        [_historyView setHistoryViewTagBlock:^(NSString *key) {
            [wekSlf loadDataSearchMethod:key];
            [wekSlf.headView skTagTapMethod:key];
        }];
        [_historyView setHotViewTagBlock:^(NSString *key) {
            [wekSlf loadDataSearchMethod:key];
            [wekSlf.headView skTagTapMethod:key];
        }];
    }
    return _historyView;
}
//空视图
- (EmptyView *)emptyView {
    
    if (!_emptyView) {
        _emptyView = [[EmptyView alloc]init];
        _emptyView.backgroundColor = [UIColor clearColor];
        _emptyView.bEmptyLabel.text = @"暂无数据";
        _emptyView.bEmptyImageView.image = [UIImage imageNamed:@"无数据"];
    }
    return _emptyView;
}
- (NSArray *)datas
{
    if (!_datas) {
        _datas = [NSArray array];
    }
    return _datas;
}
- (NSMutableArray *)allDatas
{
    if (!_allDatas) {
        _allDatas = [NSMutableArray arrayWithArray:@[@[], @[], @[]]];
    }
    return _allDatas;
}



@end
